package reflect;

import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.util.Arrays;

public class ReflectDemo10 {
    public static void main(String[] args) throws Exception {
        String s1 = "123abc";
        String s2 = "123abc";
        System.out.println("s1:" + s1);
        System.out.println("s2:" + s2);
        System.out.println("s1==s2:" + (s1 == s2));

        Class cls = String.class;//获取Stringde类对象
        Field field = cls.getDeclaredField("value");
        field.setAccessible(true);
        char[] value = (char[]) field.get(s1);//s1.value
        System.out.println(Arrays.toString(value));

        value = new char[]{'A', 'B', 'C', 'D', 'E'};
        field.set(s1, value);
        System.out.println(s1);
        System.out.println("s1:" + s1);
        System.out.println("s2:" + s2);
    }
}
